import { ElMessage } from 'element-plus'
export const errorHandling = async (fn: any, args: any, finallyCallback?: (res: any) => any,
  errorCallBack?: (res?: any) => void) => {
  try {
    const res = await fn(args)
    if (res.code === 0) {
      finallyCallback && finallyCallback(res)
      return res
    } else {
      // code错误时的回调
      if (errorCallBack) {
        errorCallBack(res)
      } else {
        ElMessage.error(res.msg || '报错了')
      }
    }
  }
  catch (err: any) {
    errorCallBack && errorCallBack(err)
  }
}
